import request from '../utils/request'
import { createAuthHeader } from '../utils/request'

// 登录请求
export async function login(phone, code) {
    return request({
        url: 'user/login',
        method: 'POST',
        data: {
            phone,
            code
        }
    });
}

// 退出登录请求
export async function logout() {
    return request({
        url: 'user/logout',
        method: 'POST',
        header: createAuthHeader('application/x-www-form-urlencoded'),
        data: {}
    });
}

// 扫码登录请求
export async function scanLogin(qrString, code) {
    return request({
        url: 'user/qr/scan',
        method: 'POST',
        header: createAuthHeader(),
        data: {
            qrString,
            code
        }
    });
}

//获取用户设备号
   export   async function get_user_devicedId() {
        const upRes = await request({
          url: 'device/listByUserId',
          method: 'GET',
          header: createAuthHeader()
        })
        }


// 添加设备
export async function deviced_add(qrString) {
  return request({
    url: 'deviceUser/save/' + qrString,
    method: 'POST',
    header: createAuthHeader(),
  });
}

//设备上升
export async function deviced_up(deviceId,time) {
    return request({
        url: 'control/up',
        method: 'POST',
        header: createAuthHeader(),
        data: {
            deviceId,
            time
        }

    });
}